/*
 *  NTPUtils.java
 * 
 *  Created on Jul 1, 2008, 11:03:36 PM
 */

package pl.edu.agh.ssm.monitor.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author aneezka
 */
public class NTPUtils {
    
    public static Date ntpToDate(String ntp) {
        try {
            double ntpVal = Double.parseDouble(ntp);
            return ntpToDate(ntpVal);
        } catch (NumberFormatException numberFormatException) {
            return null;
        }

    }
    
    public static Date ntpToDate(double ntp) {
        long millis = (long) (ntp * 1000);
        Date date = new Date(millis);
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 70);
        return calendar.getTime();
    }

}
